home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Muddweller 1.2 / source code / Externals / UArray.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  2.7 KB  |  83 lines  |  [TEXT/MPS ]

  1. /* UArray.p */
  2. /* Copyright © 1989-90 by Apple Computer, Inc. All rights reserved.*/
  3.  
  4. #ifndef  __UArray__
  5. #define __UArray__
  6.  
  7. /*    This unit implements a dynamically-sized object, called TIntegerArray, which is
  8.     an array of integers.  Each TIntegerArray can hold up to 32767 integers.
  9.  
  10.     Methods are provided for creating and initializing, as well as adding and
  11.     accessing elements of IntegerArrays.  No methods have been written for
  12.     deleting elements.
  13. */
  14.  
  15. #ifndef  __UObject__
  16. #include "UObject.h"
  17. #endif
  18.  
  19. #ifndef  __UFailure__
  20. #include "UFailure.h"
  21. #endif
  22.  
  23. #ifndef  __Packages__
  24. #include "Packages.h"
  25. #endif
  26.  
  27.  
  28. const short kElementSize     = 2;        /* size of one element (integer) */
  29. const short kIncElements    = 2;        /* number of elements to grow by */
  30.  
  31.         /* Constants for NewInitializedArray’s zero parameter */
  32. const Boolean kZeroValue    = TRUE;        /* initialize all elements to 0 */
  33. const Boolean kIntegerValue    = FALSE;    /* initialize elements to 1, 2, 3, ... */
  34.  
  35.         /* Constant for TIntegerArray.SortBy’s CompareItems function */
  36. const short kFirstGreaterThanSecond    =  1;
  37.  
  38.  
  39. class TIntegerArray    : public TObject {
  40.     public:
  41.     short fSize;        /* the number of valid elements */
  42.     /* fIntegers:    dynamic ARRAY[1..n] of INTEGER */
  43.  
  44.     virtual pascal void IArray(short elements);
  45.             /* Initialize the object to hold the specified number of elements,
  46.               and set fSize to 0. */
  47.  
  48.     virtual pascal void AddElement(short value);
  49.             /* Add an element to the array with the given value. */
  50.  
  51.     virtual pascal void AddUnique(short value);
  52.             /* Add the specified value only if it is not yet in the array */
  53.  
  54.     virtual pascal short At(short index);
  55.             /* Return the element at the given index. */
  56.  
  57.     virtual pascal void AtPut(short index, short value);
  58.             /* Change the element at the given index to value. */
  59.  
  60.     virtual pascal Boolean Contains(short value);
  61.             /* Return TRUE if the array contains the given value. */
  62.  
  63.     virtual pascal short GetSize();
  64.             /* Return the number of valid elements. */
  65.  
  66.     virtual pascal void SortBy(pascal short (*CompareItems)(short index1, short index2,
  67.         void *CompareItems_StaticLink), void *CompareItems_StaticLink);
  68.             /* Sort the elements using the given compare routine. */
  69.  
  70.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  71.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  72. };
  73.  
  74.  
  75. extern pascal TIntegerArray *NewIntegerArray(short initialSize);
  76.     /* Create a TIntegerArray big enough to hold initialSize elements */
  77.  
  78. extern pascal TIntegerArray *NewInitializedArray(short elements, Boolean zero);
  79.     /* Create a TIntegerArray with the specified number of elements, whose values are
  80.       initialized to either 0 (zero=T) or consecutive integers 1,2,3,... (zero=F). */
  81.  
  82. #endif
  83.